export default class TimeManager{
    list=new Set();
    ids=0;
    constructor(){

    }
    static get instance(){
        if(!TimeManager._instance){
            Object.defineProperty(TimeManager,"_instance",{value:new TimeManager()});
        }
        return TimeManager._instance;
    }
    add(elem){
        this.list.add(elem);
        if(this.list.size>0 && this.ids===0){
            this.ids=setInterval(()=>this.animation(),16);
        }
    }
    remove(elem){
        if(!this.list.has(elem))return;
        this.list.delete(elem);
        if(this.list.size===0 && this.ids!==0){
            clearInterval(this.ids);
            this.ids=0;
        }
    }
    animation(){
        this.list.forEach(item=>{
            item.update();
        })
    }
}